<template>
  <div class="telRegist">
    <div class="regist-title">
      <span>登录</span>
      <span class="toLogin" @click="$router.push('/regist')">我要注册</span>
    </div>
    <div class="regist-body">
      <!-- 1 -->
      <div class="common-input">
        <img
          src="https://m.ituring.com.cn/img/register-name.1418a7e0.svg"
          alt=""
        />
        <div class="input-view">
          <input
            placeholder="您的昵称"
            length="12"
            type="text"
            class="input"
            v-model="uname"
          />
        </div>
      </div>
      <!-- 2 -->
      <div class="common-input">
        <img src="https://m.ituring.com.cn/img/tel-icon.1c04fbd6.svg" alt="" />
        <div class="input-view">
          <input
            placeholder="请输入密码"
            length="12"
            type="password"
            class="input"
            v-model="upasswd"
          />
        </div>
      </div>
      <!--  -->
      <div class="btn" @click="Login">登录</div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  data() {
    return {
      uname: "",
      upasswd: "",
    };
  },
  methods: {
    // 注册方法
    Login() {
      if (this.uname && this.upasswd) {
        let users = JSON.parse(localStorage.userMsg || "[]");
        let res = false;
        for (let i = 0; i < users.length; i++) {
          let u = users[i];
          if (u.name == this.uname && u.password == this.upasswd) {
            localStorage.token = this.uname;
            res = true;
            break;
          }
        }

        if (res) {
          console.log("登录成功");
          Toast('登录成功');
          this.$router.replace("/");
        } else {
          console.log("密码错误");
          Toast('登录失败,请检查用户名与密码是否有误');
        }
      } else {
        console.log("密码不能为空");
        Toast('密码不能为空');
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.telRegist {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  z-index: 999;
  .regist-title {
    line-height: 24px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    margin: 40px 0;
    padding: 0 28px;
    span {
      color: #1e1e1e;
    }
    .toLogin {
      color: #3d5b96;
    }
  }
  .regist-body {
    .common-input {
      display: flex;
      justify-content: center;
      align-items: start;
      align-items: flex-start;
      margin-bottom: 20px;
      img {
        width: 24px;
        height: 24px;
        margin-right: 5px;
      }
      .input-view {
        .input {
          border: none;
          outline: none;
          width: 283px;
          font-size: 14px;
          line-height: 26px;
        }
        .err-view {
          color: #f62a2a;
          font-size: 12px;
          margin-top: 4px;
          line-height: 16px;
        }
      }
    }
  }
  .btn {
    background-color: var(--theme-blue);
    color: #fff;
    font-size: 16px;
    line-height: 32px;
    text-align: center;
    margin: 10px 28px;
    border-radius: 5px;
  }
}
</style>